class Queue:
    def __init__(self, size=100) -> None:
        self.queue = [0 for _ in range(size)]
        self.size = size
        self.rear = 0   # 队尾指针——进队
        self.front = 0  # 队首指针——出队

    def push(self, element):
        if not self.is_filled():
            self.rear = (self.rear + 1) % self.size
            self.queue[self.rear] = element
        else:
            raise ImportError("Queue is filled.")

    def pop(self):
        if not self.is_empty():
            self.front = (self.front + 1) % self.size
            return self.queue[self.front]
        else:
            raise IndexError("Queue is empty.")

    def is_empty(self):
        return self.front == self.rear

    def is_filled(self):
        return (self.rear + 1) % self.size == self.front

q = Queue(5)
for i in range(4):
    q.push(i)

print(q.pop())

# 内置模块
from collections import deque

q = deque()
q.append(1) # 右边进队
q.popleft() # 左边出队

q.appendleft(1) # 左边进队
q.pop() # 右边出队

qq = deque([1, 2, 3, 4, 5], 5)
qq.append(6)    # 队满了自动将第一个元素替换
qq.popleft()    # 2